import java.util.Scanner;

public class HomeWork {
    public static int[] randomArr = new int[4];
    public static int[] userArr = new int[4];

    public static void main(String[] args) {
        for (int i = 0; i < randomArr.length; i++) {
            boolean flag = true;
            int a = (int) (Math.random() * 10);//随机数
            for (int j = 0; j < i; j++) {
                if (randomArr[j] == a) {
                    flag = false;//找到重复的数，弹出重新随机
                    i--;
                    break;
                }
            }
            if (flag) {
                randomArr[i] = a;
            }
        }
        for (int item : randomArr) {
            System.out.print(item);
        }
        int count = 5;
        boolean flag = true;
        while (true) {
            Scanner scan = new Scanner(System.in);
            try {
                System.out.println("请分别输入4位数字你还有有" + count + "次机会");
                for (int l = 0; l < randomArr.length; l++) {
                    while (flag) {
                        int num = scan.nextInt();
                        if (num >= 0 && num <= 9) {
                            userArr[l] = num;
                            break;
                        }else {
                            System.out.println("输入错误，请重新输入");
                        }
                    }
                }
                count--;
            } catch (Exception e) {
                System.out.println("输入错误");
            }
            int a = 0;
            int b = 0;
            for (int k = 0; k < 4; k++) {
                if (randomArr[k] == userArr[k]) {
                    a++;
                }
                for (int o = 0; o < 4; o++) {
                    if (randomArr[k] == userArr[o]) {
                        b++;
                    }
                }
            }
            int c = b - a;
            System.out.println(a + "A" + c + "B");
            if (a == 4) {
                System.out.println("答对了");
                break;
            }
            if (count == 0) {
                System.out.println("没有机会了");
                break;
            }
        }
    }
}
